package com.example.neusoft.zyfypt_wk;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText etuser,etpass;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        init();
    }

    private void init()
    {
        findViewById(R.id.btnlogin).setOnClickListener(this);
        findViewById(R.id.btnregister).setOnClickListener(this);
        etuser=(EditText)findViewById(R.id.editText);
        etpass=(EditText)findViewById(R.id.editText2);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.btnlogin://登录
                String struser=etuser.getText().toString();
                String strpass=etpass.getText().toString();
                if(struser.equals("test")&&strpass.equals("test"))
                {
                    Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                    intent.putExtra("user",struser);
                    intent.putExtra("pass",strpass);
                    startActivity(intent);
                }
                else
                    Toast.makeText(this, "登录失败", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btnregister://注册
                Toast.makeText(this, "注册", Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent);

                break;
        }
    }
}
